var app = getApp();
var api = require('../../api.js');
var util = require('../../utils/util.js');

var myreg = /^1(?:3\d|4[4-9]|5[0-35-9]|6[67]|7[013-8]|8\d|9\d)\d{8}$/;
Page({
  data: {
    company: [],
    index: 0,
    date: '2000-09-01',
  },
  forget_password: function() {
    wx.navigateTo({
      url: '/pages/login/forget',
    })

  },
  bindDateChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },
  company_change: function(e) {
    this.setData({
      index: e.detail.value
    })
  },
  formSubmit: function(e) {
    var info = e.detail.value;
    if (info.name.length <= 0) {
      wx.showToast({
        title: '请输入正确您的姓名',
        icon: 'none'
      })
    } else if (info.phone.length != 11) {
      wx.showToast({
        title: '请输入正确的手机号码',
        icon: 'none'
      })
    } else {
      var rd_session = wx.getStorageSync('rd_session');
      if (!rd_session) {
        wx.navigateTo({
          url: '/pages/index/index',
        })
      } else {
        app.ajax(api.real_name, {
          name: info.name,
          phone: info.phone,
          birthday: info.birthday,
          rd_session: wx.getStorageSync('rd_session')
        }, (res) => {

          if (res.result == 'success') {
            if (res.is_member == "yes") {
              wx.setStorageSync("real_name", true);
            }
            wx.navigateTo({
              url: '/pages/index/wellcome',
            })

          }

        })
      }

    }
  },
  onLoad: function() {

  },
  // pages/index/wellcome 首页
  // pages/index/index 登录
  // pages/login/login 注册
  onShow() {
    var rd_session = wx.getStorageSync('rd_session');
    if (rd_session == undefined || rd_session == '') {
      wx.navigateTo({
        url: '/pages/index/index',
      })
      return false
    } else {
      var real_name = wx.getStorageSync('real_name')
      console.log(real_name)
      if (real_name == false) {
        
        return false
      } else {
        wx.reLaunch({
          url: '/pages/index/wellcome',
        })
      }
    }
  }
});